<template>
 
    <RouterView/>

</template>

<script setup>
import { RouterView } from 'vue-router';
import { onMounted } from 'vue';
import { useStore } from 'vuex';
import { useRouter } from 'vue-router';
import { menuPermissions } from './api';

const store = useStore();
const router = useRouter();

onMounted(async () => {
  const token = localStorage.getItem('pz_token');
  if (token) {
    try {
      // 重新获取菜单权限数据
      const { data } = await menuPermissions();
      store.commit('dynamicMenu', data.data);
      
      // 重新添加动态路由
      data.data.forEach(route => {
        if (!router.hasRoute(route.name)) { // 避免重复添加
          router.addRoute('main', route);
        }
      });
    } catch (error) {
     
    }
  }
});




</script>

<style lang="css" scoped>

</style>
